﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.FMCG.Buz.Models;
using Microhard.FMCG.Buz.Interfaces;
using HtmlAgilityPack;

namespace Microhard.FMCG.Buz.Impls.KASystem.WUMart
{
    public class Page302ToErrorOrTimePageParser : IHtmlParser<HtmlModel>
    {
        public HtmlModel ParseObject(string html)
        {
            HtmlModel result = new HtmlModel();
            result.Html = html;
            if (string.IsNullOrEmpty(html))
                return result;
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(html);
            var error = doc.DocumentNode.Descendants("title").Count(t => t.InnerText == "Object moved");
            if (error > 0)
            {
                result.IsError = true;
            }
            return result;
        }
    }
}
